package com.lijiajia.cloud.common.core.util;

import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Random;
import java.util.stream.Collectors;

/**
 * com.lijiajia.cloud.common.core.util description
 *
 * @author lijiajia
 * @since 2019-05-24
 */
public class NumberIdUtil {
    private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddhhmmssSSS");
    private static final long RANDOM_SIZE = 2L;
    private static final Random random = new Random();

    public static Number dateId() {
        String dateStr = OffsetDateTime.now().format(formatter);
        String randomStr = random.longs(RANDOM_SIZE, 0, 10)
                .mapToObj(String::valueOf)
                .collect(Collectors.joining());
        return Long.valueOf(dateStr.concat(randomStr));
    }
}
